package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Grouping;
import com.wuseguang.springcloud.service.GroupingService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色组 前端控制器
 * </p>
 *
 * @author 
 * @since 2019-12-06
 */
@RestController
@RequestMapping("/jurisdiction")
public class GroupingController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private GroupingService groupingServiceImpl;

    /**、
     * 查询学校的角色组
     * @param request
     * @return
     */
    @RequestMapping("/findGrouping")
    public Result findGrouping(RequestParameterWrapper request){

        logger.info("查询学校的角色组");
        String schoolId = request.getParam("schoolId");
        return groupingServiceImpl.findGrouping(schoolId);
    }

    /**
     * 修改角色组名称
     * @param request
     * @param grouping
     * @return
     */
    @RequestMapping("/updateGrouping")
    public Result updateGrouping(RequestParameterWrapper request, Grouping grouping){
        logger.info("updateGrouping");
        //判断是不是默认角色组
        if(grouping.getSchoolId()==0){
            return new Result(CodeUtil.THE_DEFAULT_OPTION_IS_NOT_OPERATIONAL);
        }
        return groupingServiceImpl.updateGrouping(grouping);
    }

    /**
     * 删除角色组
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/deleteGrouping")
    public Result deleteGrouping(RequestParameterWrapper request, @RequestParam("id")Integer id){
        logger.info("删除角色组 deleteGrouping");
        return groupingServiceImpl.deleteGrouping(id);
    }
}

